<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    protected $memberModel;
    protected $orderModel;
    public function _initialize(){
        parent::_initialize();
        $this->memberModel = D("member");
        $this->orderModel = D('order');
    }
    public function index(){
    	$this->display();
    }
    public function Index_v1(){
        ini_set('memory_limit','2048M');
        if($this->sessionInfo['parent_id'] == 0) {
            $condMemberMonth['first_class'] = $this->sessionInfo['user_id'];
            $condOrderWhere['m.first_class'] = $this->sessionInfo['user_id'];
        }else{
            $condMemberMonth['second_class'] = $this->sessionInfo['user_id'];
            $condOrderWhere['m.second_class'] = $this->sessionInfo['user_id'];
        }
        $where_main = $condMemberMonth;

        //总会员数
        $resMember = $this->memberModel->where($where_main)->count();
        $resMemberList = $this->memberModel->where($where_main)->select();


        $firstday = date('Y-m-01',strtotime(date("Y-m-d")));
        $lastday  = date('Y-m-d',strtotime("$firstday +1 month -1 day"));
        $where_main['reg_time'] = array('between',array(strtotime($firstday),strtotime($lastday)));
        //昨日会员数
        $resMemberMonth = $this->memberModel->where($where_main)->count();
        //总订单数
        if(!empty($resMemberList)){
            $condOrderWhere['o.status'] = array('in','20,30,40');
            $resOrder = $this->orderModel->alias('o')
                ->join("ecm_member m on o.buyer_id = m.user_id")
                ->where($condOrderWhere)->count();
        }else{
            $resOrder = 0;
        }
        $array = array(
            'member_month' => $resMemberMonth,
            'member' => $resMember,
            'order' => $resOrder,
        );
        $this->assign('count',$array);
        $this->display();
    }
}